<?php

require_once 'PipesImpl/Renderable.php';

class Pipes_Form_Container
{
	private $_action = '';
	private $_elements = array();
	private $_attributes = array();
	
	public function action($action) {
		$this->_action = $action;
		return $this;
	}
	
	public function add(PipesImpl_Renderable $element) {
		$this->_elements[] = $element;
		return $this;
	}
	
	public function render() {
		$attributes = array();
		foreach ($this->_attributes as $key => $value) {
			$attributes[] = htmlentities($key) . '="' . htmlentities($value) . '"';
		}
		$return = "<form action=\"{$this->_action}\" method=\"post\" " . implode(' ', $attributes) . ">\n";
		foreach ($this->_elements as $element) {
			$return .= $element->render() . "\n";
		}
		$return .= '</form>';
		return $return;
	}

	public function setAttribute($key, $value) {
		$this->_attributes[$key] = $value;
		return $this;
	}
}

